﻿using INTEX.DataBase;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Data;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class JLTAB55DOC : DocumentBase
    {
        #region-------------Properties-----------------------
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        JLTAB55DOCData m_Data;
        public DataSet dsParamaters;
        JLTAB55DOCReport m_rpt;
        public SETINTEXDB SetData
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetData");
            }
        }
        public SETINTEXDB SetProd
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetProd");
            }
        }
        #region=====vwABPOS=======
        CollectionViewSource vwABPOS
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwABPOS");
            }
        }
        DataRow dwABPOS
        {
            get
            {
                if (vwABPOS.View == null)
                    return null;
                if ((DataRowView)vwABPOS.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwABPOS.View.CurrentItem).Row;
            }
        }
        #endregion

        #region=====vwTGAAUF=======
        CollectionViewSource vwTGAAUF
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwTGAAUF");
            }
        }
        DataRow dwTGAAUF
        {
            get
            {
                if (vwTGAAUF.View == null)
                    return null;
                if ((DataRowView)vwTGAAUF.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwTGAAUF.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwGAAUF=======
        CollectionViewSource vwGAAUF
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwGAAUF");
            }
        }
        DataRow dwGAAUF
        {
            get
            {
                if (vwGAAUF.View == null)
                    return null;
                if ((DataRowView)vwGAAUF.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwGAAUF.View.CurrentItem).Row;
            }
        }
        #endregion
        string ART
        {
            get
            {
                return m_Data.Right("  " + txtArt.Text.ToString().Trim(), 2);
            }
        }
        string KRS
        {
            get
            {
                return m_Data.Right("  " + txtFKRS.Text.ToString().Trim(), 2);
            }
            set
            {
                txtFKRS.Text = value;
            }
        }
        string LFD
        {
            get
            {
                return m_Data.Right("000000" + txtFLFD.Text.ToString().Trim(), 6); ;
            }
            set
            {
                txtFLFD.Text = value;
            }
        }
        string POS
        {
            get
            {
                return m_Data.Right("000" + txtFPOS.Text.ToString().Trim(), 3); ;
            }
            set
            {
                txtFPOS.Text = value;
            }
        }
        string YKRS
        {
            get
            {
                return m_Data.Right("  " + txtYKRS.Text.ToString().Trim(), 2);
            }
            set
            {
                txtYKRS.Text = value;
            }
        }
        string YLFD
        {
            get
            {
                return m_Data.Right("000000" + txtYLFD.Text.ToString().Trim(), 6); ;
            }
            set
            {
                txtYLFD.Text = value;
            }
        } 
        BindingListCollectionView cvTGAAUF
        {
            get
            {
                return (BindingListCollectionView)CollectionViewSource.GetDefaultView(dlgTGAAUF.ItemsSource);
            }
        }
        #endregion
        public JLTAB55DOC()
        {
            InitializeComponent();
            this.Name = "织造生产";

        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            dsParamaters = (DataSet)dicParamater["dsParamaters"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            m_Data = new JLTAB55DOCData(OracleDB, proxy);
            KRS = "ZZ ";
            LFD = "000010";
            POS = "001";
            
            m_rpt = new JLTAB55DOCReport();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
             

        }

        void View_CurrentChanged(object sender, EventArgs e)
        {/*
            if (dwTBABST == null)
                return;
            txtKART.Text = dwTBABST["BMKART"].ToString();
            txtKFARBE.Text = dwTBABST["BMFARBE"].ToString();*/
        }
        private void btnQuery_Click(object sender, EventArgs e)
        {
            DataSet Result = new DataSet();
            DataRow row = SetData.ABPOS.NewRow();
            row["ABPMANDANT"] = "00";
            row["ABPAUFKRS"] = KRS;
            row["ABPAUFLFD"] = LFD;
            row["ABPAUFPOS"] = POS;
            Result = m_Data.BuildData(row);
            SetData.Clear();
            SetData.Merge(Result, false, MissingSchemaAction.Ignore);
            if (vwABPOS != null)
            {
                if (vwABPOS.View != null)
                {
                    vwABPOS.View.MoveCurrentToFirst();
                }
            }
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {

            m_rpt.dsSource = SetData;
            m_rpt.doctype = "ABDOC";
            m_rpt.WriteExcelReport("OpenExcel");
        } 

        private void btnFilter_Click(object sender, RoutedEventArgs e)
        {
            //string filter = "BMKART LIKE '" + txtKART.Text.Trim() + "%' AND BMFARBE LIKE '" + txtKFARBE.Text.ToString().Trim() + "%'";
            //cvTBABST.CustomFilter = filter;
        }

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            //cvTBABST.CustomFilter = null;
        }

        private void btnQueryAB50_Click(object sender, RoutedEventArgs e)
        {
            DataSet Result = new DataSet();
            DataRow row = SetData.ABPOS.NewRow();
            row["ABPMANDANT"] = "00";
            row["ABPAUFKRS"] = YKRS;
            row["ABPAUFLFD"] = YLFD;
            row["ABPART"] =Helpers.Helper.Left(txtFArt.Text.ToString().PadRight(20),20);
            row["ABPFARBE"] = txtFArt.Text.ToString().PadRight(30).Substring(8, 10);
            Result = m_Data.QueryAB50(row);
            SetData.Clear();
            SetData.Merge(Result, false, MissingSchemaAction.Ignore);
            if (vwGAAUF != null)
            {
                if (vwGAAUF.View != null)
                {
                    vwGAAUF.View.MoveCurrentToFirst();
                }
            }
        }

        private void btnPrintYarn_Click(object sender, RoutedEventArgs e)
        {
            m_rpt.dsSource = SetData;
            m_rpt.doctype = "WEFTYARN";
            m_rpt.WriteExcelReport("OpenExcel");
        }

        private void btnPrintPiece_Click(object sender, RoutedEventArgs e)
        {
            m_rpt.dsSource = SetData;
            m_rpt.doctype = "WBBST";
            m_rpt.WriteExcelReport("OpenExcel");
        } 
    }
}
